char *z[101000],b[1019090],res[1010000];int n,cnt,resn;
#define I(p) z[n]=p;n++;
int nq(char*s,char*d,int n){while(n--&&*s++==*d++);return n+1;}void cp(char*s,char*d,int n){while(*s,*d++=*s++,n--);*d=0;}int little(char*s,char*d,int n){while(n--&&*s++<=*d++);return n==-1;}void main(){char*s=b,*t,*r,*v,*k;int i,sonl;while(gets(s)&&*s-35){while(*s){if (cnt==0){if(*res==0)*res=*s;if(*s<*res)*res=*s;}t=s+1;while(*t){while(*t&&*t++-*s);if(*t--){v=t;I(v);for(i=1;i;){k=(v+i*(v-s));if(*k==*s){i++;I(k)}else{i=0;}}for(i=n;i>0;i--){if(nq(s,z[i-1],v-s)){n--;}}if(n>0){sonl=(n+1)*(v-s);if(sonl>cnt||(sonl==cnt&&little(s,res,sonl))){cp(s,res,sonl);res[sonl]=0;cnt=sonl;}}n=0;}t++;}s++;}cnt=0;printf("Case %d: %s\n",++resn,res);*res=res[1]=0;}}